cmake_minimum_required(VERSION 3.14)

project(mediawiki-analyzer LANGUAGES CXX VERSION 1.1.0)

include(cmake/SparkWithGit.cmake)
spark_initialize_modules()

spark_add_links_qt(
     WebEngine
     WebEngineWidgets
)

# 资源文件路径
set(QRC_SOURCES "src/res/res.qrc")

if(MSVC)
    # MSVC 编译器处理方案，支持 utf-8 编码的项目
    add_compile_options(/utf-8)
endif(MSVC)

spark_add_executable_path(${PROJECT_NAME} 
    src
    src/config
    src/dialog
    src/dialog/subdialog
    src/widgets
    src/wiki
    src/wiki/gitee
    src/wiki/github
    src/wiki/linkwiki
    src/wiki/searchwiki
    ${QRC_SOURCES}
    src/icon.rc
)
target_link_qt(${PROJECT_NAME})
target_link_qt_WebEngineWidgets(${PROJECT_NAME})

spark_framework_include_with_git(${PROJECT_NAME} 
    https://gitee.com/spark-framework-libs/spark-framework-features
    FEATURES qd qrcutil version screenutil)

spark_framework_include_with_git(${PROJECT_NAME}
    https://gitee.com/spark-framework-libs/network-access-libs
    FEATURES httpmanager)

spark_framework_include_with_git(${PROJECT_NAME}
    https://gitee.com/spark-framework-libs/simple-frameless-libs
    FEATURES frameless)

# 示例集合
option(ENABLE_BUILD_EXAMPLES "Enable Build Examples." OFF)
if(ENABLE_BUILD_EXAMPLES)
    include(examples/dev.cmake)
endif(ENABLE_BUILD_EXAMPLES)

# 测试集合
option(ENABLE_BUILD_TESTS "Enable Build Tests." OFF)
if(ENABLE_BUILD_TESTS)
    add_subdirectory(tests)
endif(ENABLE_BUILD_TESTS)



# Debian 系列打包
if(EXISTS /etc/debian_version)
    set(LINUX_DEBIAN 1)
    if (CMAKE_VERSION VERSION_LESS 3.25)
        set(LINUX 1)
    endif()
endif(EXISTS /etc/debian_version)

if(LINUX AND LINUX_DEBIAN)
    spark_install_target(/usr/bin ${PROJECT_NAME})
    spark_install_file(/usr/share/${PROJECT_NAME}/ src/res/icon.png)
    spark_desktop_macros(
        # 应用名称: Name=
        "MediaWiki Analyzer"
        # 应用名称: Name[zh_CN]=
        "MediaWiki 分析器"
        # 应用说明: Comment=
        ""
        # 应用类型: Type=
        "Application"
        # 执行程序: Exec=
        "${PROJECT_NAME}"
        # 图标路径: Icon=
        "/usr/share/${PROJECT_NAME}/icon.png"
        # 应用分类: Categories=
        "AudioVideo"
        # MIME类型: MimeType=
        ""
    )
    spark_install_file(/usr/share/applications ${SPARK_DESKTOP_FILE})

    add_package_descript(cmake/spark-deb-package.descript)

    # include(cmake/SparkAppimageConfig.cmake)  # 导入来自 Spark 构建的 Appimage 构建
    add_appimage_icon(src/res/icon.png)       # 添加到 Appimage 中的默认的图标
    add_appimage_desktop()                    # 添加到 Appimage 中的默认desktop(使用来自 Spark 构建的 Desktop 构建中配置的信息(必须要求 spark-desktop))
    add_appimage_target(${PROJECT_NAME})      # 添加到 Appimage 中的默认目标，应用对 Appimage 的构建

endif(LINUX AND LINUX_DEBIAN)
